/**
 * 提供各种js验证：
 * 高氏验证法
 */

/**
 *邮箱格式检测---------------------------开始
 */
//检查邮箱名是否合法:方法一
function isValidMailRough(str) {

	if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		return true;
	}
	return false;
}

//检查邮箱名是否合法:方法二
function isValidMailDetail(str) { 
	str = str.trim();//去掉字符串前后的空格
	var i; 
	var errorChar;
	var length = str.length;//长度
	if(str == null || length <= 0 ){
		errorChar = "邮箱名不能为空!";
		return errorChar;
	}
	for(i=0;i<length;i++){
		if(!char_test(str.charAt(i))){ 
			errorChar = "邮箱名只能包含_,英文字母,数字和 .";
			return errorChar;
		}
	}
	//检测“@”的位置 

	if("@" == str.charAt(0) || "@" == str.charAt(length-1)) {
		errorChar = "邮箱首字符和末尾字符不能是@";
		return errorChar; 
	}

	if (str.indexOf("@") == -1 || str.indexOf(".") < 0) {
		errorChar = "邮箱名必须包括 @ 和 . ";
		return errorChar;
	}
	var split = str.split("@");
	if(split.length > 2 ){
		errorChar = "邮箱名只能包含一个@！";
		return errorChar;
	}
	if(split[split.length-1].indexOf(".") < 0){
		errorChar = "邮箱服务器名不合法！";
		return errorChar;
	}
	return "";
}
//字符检测函数 
function char_test(chr) {
	var test="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.@0123456789"; 
	if(test.indexOf(chr) !=-1){ 
		return true; 
	}
	return false; 
} 
/**
 *邮箱格式检测---------------------------结束
 */


//检查手机号是否合法:粗略
function isMobileNo(s){
	var reg = /^1[34578][0-9]{9}$/;	
	if(reg.exec(s)) {
		return true;
	}
	return false;
}

//特殊字符检测函数
function isSpecialChar(s) {
	var reg = /^(([^\^\.<>%&';=?$"':#@!~\]\[{}\\/`\|])*)$/;
	if(reg.exec(s)) return true;
	else return false;
}

/**
 *验证电话号码和手机号码
 */
function isPhoneNo(s){
	var reg = /(^[0-9]{3,4}\-{0,1}[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^1[34578]\d{9}$)/;	
	if(reg.exec(s)) return true;
	else return false;
}

/**
 *验证银行卡帐号（19位和23位) 正则表达式： /^(\d{4}[\s\-]?){4,5}\d{3}$/g
 * 下面是验证15-23位的银行帐号
 */
function isBankAccountNo(s){
	var reg = /^(\d{5}[\s\-]?){3}\d{0,8}$/g;	
	if(reg.exec(s)) return true;
	else return false;
}

/**
 * 验证真实姓名
 */
function validateRealName(s){
	var reg = /^[\u4e00-\u9fa5]+$/;
	if(s.gblen()<4 || s.gblen()>20) {
		return false;
	} else if (!reg.exec(s)) {
		return false;
	} else {
		return true;
	}
}

/**
 * 客户端检查敏感词:简易检查
 * @param content 待检查的字符串
 * @return 没有敏感词返回空串
 */
function checkDenyWords(content) {
	if (content == null || content.trim() == "") return "";
	var wordsArrays = new Array();
	wordsArrays = new Array("≡V≡","≡v≡","admin","AIDS","aids","Aids","asshole","bitch","bitch","BITCH","Dick","fuck","fuck","FUCK","G.M","g.m","G。M","g。m","GM","GM","gm","Gm","gM","GT","j8","J8","LB","lb","SARS","SB","sb","SG","suck","阿扁","阿拉法特","艾滋","艾滋病","白鸟敏夫","板垣征四郎","包皮","本·拉登","本拉登","笨屄","笨逼","屄","逼","逼毛","冰毒","布莱尔","布什","操顺网","操妳","操妳老妈","操妳老母","操妳妈","操妳娘","操妳祖宗","操你","操你大爷","操你老妈","操你老母","操你妈","操你妈个B","操你妈个屄","操你娘","操你全家","操你祖宗","操死顺网","曹刚川","肏","插妳","插你","朝鲜","陈伯达","陈良宇","陈水扁","陈云","处女膜","春药","达赖","达子","打倒","大花B","大麻","大卫教","大血B","代练","代言","带练","党主席","道教","邓小平","帝国主义","屌","东条英机","东突暴动和独立","东乡茂德","东亚病夫","毒贩","独立","二屄","二逼","法高","法轮","法轮功","法西斯","佛教","佛祖","干妳","干妳老妈","干妳老母","干妳妈","干妳娘","干你","干你老妈","干你老母","干你妈","干你娘","肛交","高丽棒子","膏药旗","共产党","共产主义","共匪","挂机","观世音","广田宏毅","龟头","郭伯雄","国民党","国务院","海洛因","贺国强","黑社会","黑手党","胡锦涛","胡启立","胡耀邦","花柳","华国锋","黄菊","回回","回教","回良玉","鸡八","鸡巴","鸡奸","基督","基督教","激情图片","激情写真","妓女","贾庆林","奸","江core","江泽民","蒋介石","蒋经国","蒋中正","金日成","金正日","巨乳","康生","尻","克林顿","口交","寇晓伟","狂操","拉登","拉姆斯菲尔德","烂B","烂逼","烂人","老卵","李长春","李登辉","李富春","李洪志","李岚清","李鹏","李瑞环","李先念","连战","林彪","淋病","刘华清","刘淇","刘少奇","刘云山","六四","吕秀莲","乱伦","罗干","裸体写真","裸照","妈的顺网","妈祖","马晓轶","毛泽东","梅毒","梅津美治郎","美国","蒙古","密宗","民进党","摩门教","木村兵太郎","穆罕默德","穆斯林","内挂","妳老母的","妳妈的","南蛮子","你姥","你姥姥的","你妈的","捻","娘","女干","女马","屁眼","嫖","平沼骐一郎","仆街","普京","强奸","强奸犯","乔石","亲民党","屈江涛","去死","人妻","日","日GT","日本","日本鬼子","日你妈","日你娘","日死顺网","乳房","乳头","萨达姆","塞你爸","塞你公","塞你老母","塞你母","塞你娘","傻B","傻屄","傻逼","傻比","山本五十六","上妳","上你","社会主义","圣母","圣战","兽交","死顺网","松冈洋右","松井石根","宋楚瑜","宋平","素人","孙文","孙逸仙","孙中山","他妈的","台独","台联","台湾","台湾独立","陶铸","天安门","天皇","土肥原贤二","外挂","汪东兴","王刚","王乐泉","王迁唐","王兆国","尉健行","温家宝","我操","我考","我靠","吴邦国","吴官正","吴俊青","吴仪","武藤章","西藏独立","西藏喇嘛","希拉克","希拉里","希特勒","系统","鲜族","萧汉华","小矶国昭","小泉纯一郎","小日本","新党","新闻出版总署","性交","性欲","鸦片","阳痿","姚依林","摇头丸","耶和华","耶稣","耶稣","叶剑英","一贯道","一丝不挂","伊斯兰","阴道","阴蒂","阴茎","阴毛","淫","永野修身","幼齿","俞正声","早泄","曾培炎","曾庆红","张春桥","张德江","张立昌","赵紫阳","真理教","真世界","中共","中共中央","中国共产党","中华民国","中南海","中宣部","中央电视台","周恩来","周永康","朱德","朱金容基","朱容基","朱镕基","转法轮","装屄","装逼","总理","作爱","做爱","扣逼","抠逼","客服");
	for(var k=0;k<wordsArrays.length;k++){
		if (content.indexOf(wordsArrays[k])!=-1){
			return wordsArrays[k];
		}
	}
	return "";
}

/*
 *功能：验证身份证号码是否有效
 *提示信息：未输入或输入身份证号不正确！
 *使用：validateIdCard(obj)
 *返回：0:正确,1：非法身份证号,2：非法地区,3：非法生日
 */
function validateIdCard(strIDno){
	var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};
	var iSum = 0;
	var idCardLength = strIDno.length;
	if(!/^\d{17}(\d|x)$/i.test(strIDno)&&!/^\d{15}$/i.test(strIDno))
		return 1; //非法身份证号

	if(aCity[parseInt(strIDno.substr(0,2))]==null)
		return 2;// 非法地区

	// 15位身份证转换为18位
	if (idCardLength==15){
		sBirthday = "19" + strIDno.substr(6,2) + "-" + Number(strIDno.substr(8,2)) + "-" + Number(strIDno.substr(10,2));
		var d = new Date(sBirthday.replace(/-/g,"/"))
		var dd = d.getFullYear().toString() + "-" + (d.getMonth()+1) + "-" + d.getDate();
		if(sBirthday != dd)
			return 3; //非法生日
		strIDno=strIDno.substring(0,6)+"19"+strIDno.substring(6,15);
		strIDno=strIDno+GetVerifyBit(strIDno);
	}

	// 判断是否大于2078年，小于1900年
	var year =strIDno.substring(6,10);
	if (year<1900 || year>2078 )
		return 3;//非法生日

	//18位身份证处理

	//在后面的运算中x相当于数字10,所以转换成a
	strIDno = strIDno.replace(/x$/i,"a");

	sBirthday=strIDno.substr(6,4)+"-"+Number(strIDno.substr(10,2))+"-"+Number(strIDno.substr(12,2));
	var d = new Date(sBirthday.replace(/-/g,"/"))
	if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))
		return 3; //非法生日
	// 身份证编码规范验证
	for(var i = 17;i>=0;i --){
		iSum += (Math.pow(2,i) % 11) * parseInt(strIDno.charAt(17 - i),11);
	}
	if(iSum%11!=1)
		return 1;// 非法身份证号

	// 判断是否屏蔽身份证
	var words = new Array();
	words = new Array("11111119111111111","12121219121212121");

	for(var k=0;k<words.length;k++){
		if (strIDno.indexOf(words[k])!=-1){
			return 1;
		}
	}

	return 0;
}

/**
 *15位转18位身份证号码---------------------------开始
 */

function Get18(idCard){
	if (CheckValue(idCard)){
		var id = idCard;
		var id18=id;
		if (id.length==0){
			alert("请输入15位身份证号！");
			return false;
		}
		if (id.length==15){
			if (id.substring(6,8)>20){
				id18=id.substring(0,6)+"19"+id.substring(6,15);
			}else{
				id18=id.substring(0,6)+"20"+id.substring(6,15);
			}
			id18=id18+GetVerifyBit(id18);
		}
		return id18;
	}else{
		return false;
	}
}
//15位转18位中,计算校验位即最后一位
function GetVerifyBit(id){
	var result;
	var nNum=eval(id.charAt(0)*7+id.charAt(1)*9+id.charAt(2)*10+id.charAt(3)*5+id.charAt(4)*8+id.charAt(5)*4+id.charAt(6)*2+id.charAt(7)*1+id.charAt(8)*6+id.charAt(9)*3+id.charAt(10)*7+id.charAt(11)*9+id.charAt(12)*10+id.charAt(13)*5+id.charAt(14)*8+id.charAt(15)*4+id.charAt(16)*2);
	nNum=nNum%11;
	switch (nNum) {
	case 0 :
		result="1";
		break;
	case 1 :
		result="0";
		break;
	case 2 :
		result="X";
		break;
	case 3 :
		result="9";
		break;
	case 4 :
		result="8";
		break;
	case 5 :
		result="7";
		break;
	case 6 :
		result="6";
		break;
	case 7 :
		result="5";
		break;
	case 8 :
		result="4";
		break;
	case 9 :
		result="3";
		break;
	case 10 :
		result="2";
		break;
	}
	//document.write(result);
	return result;
}
/**
 *15位转18位身份证号码---------------------------结束
 */

//ip地址是否合法----------开始
function isIp(In_Str){
	var ipArr = In_Str.split(".");
	var errorChar;
	var reg = /^[\u4e00-\u9fa5]+$/;
	if(!reg.exec(In_Str)==false){
		errorChar = "ip地址输入不合法";
		return errorChar;
	}
	if(ipArr.length !=4){
		errorChar = "ip地址输入不合法";
		return errorChar;
	}
	for(var i=0;i<ipArr.length;i++){
		if(!checkIpNumber(ipArr[i])){
			errorChar = "ip地址输入不合法";
			return errorChar;
		}
	}

	return "";
}

function checkIpNumber(In_Str){
	var	Ret_Value = true;
	for (i=0; i<StrLen.length; i++){
		FirstCha = escape(In_Str.charAt(i));
		if ((FirstCha < "0") || (FirstCha > "9")){
			return false;
		}
	}
	if(parseInt(In_Str)>255){
		return false;
	}
	return true;
}
//ip地址是否合法----------结束

//判断url地址是否合法
function checkURL(url){
	var reg = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
	if(!reg.test(url)){
		return false;
	}
	return true;
}

//判断汉字:true是汉字，false：不是汉字
function checkCHN(str){
	var reg = /^[\u4e00-\u9fa5]+$/;
	if(!reg.test(str)){
		return false;
	}
	return true;
}

//只能输入字母.数字和下划线
function checkNum(str){
	var reg =/^\w+$/; 
	if(reg.test(str)){
		return true;
	}
	return false;
}

//只能输入英文字母
function checkEn(str){
	var reg = /^[a-z]*$/i; 
	if(reg.test(str)) { 
		return true; 
	} 
	return false;
}

//匹配非负整数、正整数
function isPlusInt(str){
	var reg = /^[0-9]*$/;
	if(reg.test(str)){
		return true;
	}
	return false;
}

//匹配整数
function isInt(str){
	var reg = /^-?\d+$/;
	if(reg.test(str)){
		return true;
	}
	return false;
}

//匹配小数
function isDecimal (str){
	var reg = /^\d+\.\d+$/;//正小数
	//var reg =  /^-\d+\.\d+$/;//负小数
	if(reg.test(str)){
		return true;
	}
	return false;
}

//保留小数位
function keepDecimals(str){
	var reg = /^-?\d+\.?\d{0,1}$/;//保留1位小数
	//var reg = /^-?\d+\.?\d{0,2}$/;//保留2位小数
	//var reg = /^-?\d+\.?\d{0,3}$/;//保留3位小数
	if(reg.test(str)){
		return true;
	}
	return false;
}

//匹配整数或两位小数
function validateNumber(str){
	var patn =/^[-1000000-9]+([.]\d{0,2})?$/;
	return patn.test(str)
}

//校验是否全由数字组成  --cjh
function isDigit(s){
	var patrn=/^[0-9]{1,20}$/;
	if (!patrn.exec(s)) {	  
	   return false;
	  }
	
	return true;
	}
// 短日期，形如 (2003-12-05)判断日期格式符合YYYY-MM-DD标准 
function   checkDate(strDate){ 
	re=/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
	if(re.test(strDate)){ 
	  return true;
	  }
	 return false
}
/**
 *js验证目录：
 *邮箱验证：7-66
 *手机验证：69
 *验证手机号码和电话号码：78
 *银行卡账户验证：87
 *验证真实姓名:97
 *客户端检查敏感词:111
 *验证身份证号码是否有效:127-187
 *15位身份证转18位身份证：189-259
 *ip地址是否合法:263-299
 *判断url地址是否合法:301
 *判断是否是汉字：310
 *只能输入字母.数字和下划线:319
 *只能输入英文字母:328
 *匹配非负整数:337
 *匹配整数:346
 *匹配小数:355
 *保留小数位:365
 *匹配整数或两位小数:376
 */

//注册验证
/**
 * @description 去除首尾空格
 * @constructor TrimSpace
 * @example new TrimSpace();
 */
function TrimSpace() {
}

/**
 * @description 执行校验
 * @param obj
 *            校验对象
 */
TrimSpace.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^[\s|　]*)|([\s|　]*$)/g, "");
    obj.val(value);
}

/**
 * @description 判断是否为空
 * @constructor CheckEmpty
 * @param option
 *            JSON对象
 * @example new CheckEmpty({msg:'此项不能为空'});
 */
function CheckEmpty(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;
}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckEmpty.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    if (value.length < 1) {
        throw this.msg;
    }
}

/**
 * @description 验证账号为全中文，且长度超过16个字符
 * @constructor length
 * @param option
 *            JSON对象
 * @example new CheckChainPassport({msg:'纯中文账号不能超过8个汉字',length:'16'});
 */
function CheckChainPassport(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;

    /**
     * @description {Num} 最大长度
     * @field
     */
    this.length = option.length;
}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckChainPassport.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    var getLength = value.replace(/[^\x00-\xff]/g, "**").length;
    var patrn = /^[\u4E00-\u9FA5]+$/;
    if (!patrn.exec(value)) {
        return true;
    }
    if (getLength > this.length) {
        throw this.msg;
    }
}
/**
 * @description 验证最大长度
 * @constructor CheckMaxLength
 * @param option
 *            JSON对象
 * @example new CheckMaxLength({msg:'最大长度不可超过16位',length:'16'});
 */
function CheckMaxLength(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;
    /**
     * @description {Num} 长度
     * @field
     */
    this.length = option.length;
}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckMaxLength.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    var getLength = value.replace(/[^\x00-\xff]/g, "**").length;
    if (getLength < 1)
        return true;
    if (getLength > this.length) {
        throw this.msg;
    }
}
/**
 * @description 验证长度区间
 * @constructor CheckLength
 * @param option
 *            JSON对象
 * @example new CheckLength({msg:'长度区间是6－16位',maxLength:'16',minLength:'6'});
 */
function CheckLength(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;
    /**
     * @description {Num} 最大长度
     * @field
     */

    this.maxLength = option.maxLength;
    /**
     * @description {Num} 最小长度
     * @field
     */
    this.minLength = 0;
    if (option.minLength)
        this.minLength = option.minLength;
}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckLength.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    var len = value.replace(/[^\x00-\xff]/g, "**").length;
    if (this.maxLength < len || len < this.minLength) {
        throw this.msg;
    }
}

/**
 * @description 是否有空格验证
 * @constructor CheckSpace
 * @param option
 *            JSON对象
 * @example new CheckSpace({msg:'账号中不能包含空格'});
 */
function CheckSpace(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;

}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckSpace.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    var patn = /\s+/;
    if (patn.test(value)) {
        throw this.msg;
    }
}

/**
 * @description 验证通行证账号
 * @constructor CheckPassport
 * @param option
 *            JSON对象
 * @example new CheckPassword({msg:'不能纯数字,仅支持字母、数字、下划线、#和中文'});
 */
function CheckPassport(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;
}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckPassport.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    if (value.length < 1)
        return true;
    var singleCount = (/^[0-9]+$/).test(value);
    var pattern = (/^[a-zA-Z0-9_#\u4e00-\u9fa5]+$/).test(value);
    if (singleCount)
        throw "账号不能是纯数字";
    if (!pattern)
        throw this.msg;
}

/**
 * @description 验证密码是否为同一个字符
 * @constructor CheckPasswordSingle
 * @param option
 *            JSON对象
 * @example new CheckPasswordSameOne({msg:'密码是否为同一个字符'});
 */
function CheckPasswordSameOne(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;
}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckPasswordSameOne.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    if (value.length < 1){
        return true;
    }
    var ch = value.substring(0, 1);
    var str = "";
    for(var i=0; i<value.length; i++){
        str += ch;
    }
    if(str == value){
        throw this.msg;
    }
}

/**
 * @description 验证密码
 * @constructor CheckPassword
 * @param option
 *            JSON对象
 * @example new CheckPasswordSingle({msg:'密码不能为连续的字母，数字和字符'});
 */
function CheckPassword(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;
}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckPassword.prototype.validate = function(obj) {
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    if (value.length < 1)
        return true;
    var pattern = (/^[a-zA-Z0-9_#]+$/).test(value);
    if (!pattern) {
        throw this.msg;
    }
}

/**
 * @description 验证确认密码
 * @constructor CheckRePassword
 * @param option
 *            JSON对象
 * @example new CheckRePassword({msg:'确认密码输入不一致',password:'id'});
 */
function CheckRePassword(option) {
    /**
     * @description {String} 错误提示信息
     * @field
     */
    this.msg = option.msg;

    this.password = option.password;

}
/**
 * @description 执行校验
 * @param obj
 *            校验对象
 * @throws msg
 *             错误提示信息
 */
CheckRePassword.prototype.validate = function(obj) {
    var password = $("#" + this.password).val();
    var value = obj.val().replace(/(^\s*)|(\s*$)/g, "");
    var rePassword = value;
    if (password != rePassword) {
        throw this.msg;
    }
}
/** ValidateRule End * */

function Validate(rule, obj, errorId) {
    /**
     * @description {Object} 校验对象
     * @field
     */
    this.obj = obj;
    this.errorId = errorId;
    /**
     * @description {Object} 校验规则对象
     * @field
     */

    var ruleArr = new Array();
    if (rule) {
        var len = rule.length;
        for ( var i = 0; i < len; i++)
            ruleArr.push(rule[i]);
    }
    this.ruleArr = ruleArr;
}

/**
 * @description 执行校验
 */
Validate.prototype.validate = function() {
    try {
        for ( var i in this.ruleArr) {
            this.getMsgObj().html('');
            this.ruleArr[i].validate(this.obj);
        }
    } catch (msg) {
        this.obj.focus();
        this.getMsgObj().html(msg).show();
        throw msg;
    }
}

Validate.prototype.clear = function() {
    this.obj.val('');
    this.getMsgObj().html('');
};
/**
 * 返回msg对象
 */
Validate.prototype.getMsgObj = function() {
    return $("#" + this.errorId);
}

/** ValidatePanel Begin * */
/**
 * 验证面板的集合
 */
var ValidatePanel = function(param,errorId) {
    this.rulesMap = {};
    for ( var key in param.rules) {
        this.rulesMap[key] = new Validate(param.rules[key], $('#' + key), errorId);
    }
}
/**
 * 进行检查
 */
ValidatePanel.prototype.check = function() {
    if (this.rulesMap) {
        var rules = this.rulesMap;
        for ( var e in rules) {
            try {
                rules[e].validate();
            } catch (e) {
                return false;
            }
        }
    }
    return true;
}

ValidatePanel.prototype.clear = function() {
    if (this.rulesMap) {
        var rules = this.rulesMap;
        for ( var e in rules) {
            rules[e].clear();
        }
    }

}

/**
 * 检查某一个控件
 */
ValidatePanel.prototype.checkById = function(id) {
    var rules = this.rulesMap;
    if (rules) {
        var rule = rules[id];
        if (rule) {
            try {
                rule.validate();
            } catch (e) {
                return false;
            }
            return true;
        }
    }
    return true;
}

/**
 * 某一个控件失去焦点
 */
ValidatePanel.prototype.lostFocus = function(id) {
    this.checkById(id);
}
